import {useNavigate} from "react-router-dom";
import {useEffect, useState} from "react";

import {message} from "antd";
import {getCommonMaterialsInfoAPI} from "@/apis/commonMaterials.jsx";


const useGetCommonMaterialsById = (id) => {
    const navigator = useNavigate();
    const [commonMaterials, setCommonMaterials] = useState({});
    useEffect(() => {
        const getOneCommonMaterialsById = async () => {
            const res = await getCommonMaterialsInfoAPI(id);
            if (res.code === 200) {
                setCommonMaterials(res.data);
            }
            else if (res.code === 500) {
                message.error(res.msg);
                navigator('/backgroundManage/commonMaterials')
            }
        }
        getOneCommonMaterialsById().then()
    }, [])
    return commonMaterials;
}

export {
    useGetCommonMaterialsById
}